package com.carleasoft.mps.cms.business.collector.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.collector.bean.entity.CollectorEntity;
import com.carleasoft.mps.cms.business.collector.bean.po.CollectorPos;
import com.carleasoft.mps.cms.business.collector.service.CollectorService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收藏
 * @author: yangHao
 * @createDate:2023/6/17
 * @description:
 */
@RestController
@RequestMapping("/collector")
public class CollectorController {
    @Autowired
    private CollectorService collectorService;


    /**
     * 添加收藏
     *
     * @param collectorEntity
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody CollectorEntity collectorEntity) {
        IBeanUtil.paramVerify(collectorEntity, "code", "name", "type");
        boolean isOk = collectorService.saveCollector(collectorEntity);
        return R.ok(isOk);
    }

    /**
     * 取消收藏
     *
     * @param collectorEntity
     * @return
     */
    @PostMapping("/delete")
    public R delete(@RequestBody CollectorEntity collectorEntity) {
        IBeanUtil.paramVerify(collectorEntity, "code");
        boolean isOk = collectorService.delete(collectorEntity);
        return R.ok(isOk);
    }

    /**
     * 查询列表
     *
     * @return
     */
    @PostMapping("/list")
    public R list(@RequestBody CollectorPos collectorEntity) {
        Page<CollectorEntity> collectorEntityList = collectorService.collectorList(new Page(collectorEntity.getCurrent(),collectorEntity.getSize()),collectorEntity);
        return R.ok(collectorEntityList);
    }

}
